home *** CD-ROM | disk | FTP | other *** search
- // ******************* File: prog8.C *****************
- // Demonstration of least squares spline approximation
- #include <BSpline.h>
- int main()
- {
- // The data are 10 discrete points:
- VecSimple(real) x(10),f(10);
- x.scan("1.1 1.5 1.8 2.1 2.2 2.4 3.4 3.6 4.2 4.8");
- for (int i=1; i<=10; i++) f(i)=4*x(i)*x(i)*x(i)+3*x(i);
-
- KnotVec knots(5);
- knots.scan("1 2 3 4 5"); // alternative to knots.fill(1,5)
- knots.regulate(4);
- knots.print(s_o,"knot vector");
- x.print(s_o,"x data"); f.print(s_o,"f data");
-
- SplineSpace space(knots,4); // cubic spline
- BSpline spline;
- spline.redim(space);
- spline.leastSquareInterpolation(x,f);
- s_o <<"cubic spline at x=2.0 : " << spline(2.0) <<'\n';
- return 0;
- }
-